package claybird.dao;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import claybird.dom.ShootDay;
import claybird.dom.Team;

@Repository
@Transactional
@SuppressWarnings("unchecked")
public class TeamDao extends BaseRepository<Team>{
	
	 public  List<Team> getAllTeam(){
	        return em.createQuery("select a from Team a").getResultList();
	    }
	 public List<Team> getAllTeamSortedByResult(ShootDay day){
		 return em.createQuery("select t from Team t where t.shootDay = :day order by t.ranking").setParameter("day", day).getResultList();
	 }
	public float getBestStrength(ShootDay shootDay) {
		if(em.createQuery("select t.averageHandicap from Team t where t.shootDay = :day order by t.averageHandicap").setParameter("day", shootDay).getResultList().size()>0){
			return (float) em.createQuery("select t.averageHandicap from Team t where t.shootDay = :day order by t.averageHandicap").setParameter("day", shootDay).getResultList().get(0);
		}
		return 0;
	}
	public List<Team> getAllTeamForShootDay(ShootDay shootDay) {
        return em.createQuery("select a from Team a where a.shootDay = :shoot")
        		.setParameter("shoot", shootDay).getResultList();
	}
	 
}
